package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Newroad;
import com.ruoyi.system.service.INewroadService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 路段管理Controller
 * 
 * @author xjj
 * @date 2022-04-08
 */
@RestController
@RequestMapping("/system/newroad")
public class NewroadController extends BaseController
{
    @Autowired
    private INewroadService newroadService;

    /**
     * 查询路段管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:newroad:list')")
    @GetMapping("/list")
    public AjaxResult list(Newroad newroad)
    {
        List<Newroad> list = newroadService.selectNewroadList(newroad);
        return AjaxResult.success(list);
    }

    /**
     * 导出路段管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:newroad:export')")
    @Log(title = "路段管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Newroad newroad)
    {
        List<Newroad> list = newroadService.selectNewroadList(newroad);
        ExcelUtil<Newroad> util = new ExcelUtil<Newroad>(Newroad.class);
        util.exportExcel(response, list, "路段管理数据");
    }

    /**
     * 获取路段管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:newroad:query')")
    @GetMapping(value = "/{roadId}")
    public AjaxResult getInfo(@PathVariable("roadId") Long roadId)
    {
        return AjaxResult.success(newroadService.selectNewroadByRoadId(roadId));
    }

    /**
     * 新增路段管理
     */
    @PreAuthorize("@ss.hasPermi('system:newroad:add')")
    @Log(title = "路段管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Newroad newroad)
    {
        return toAjax(newroadService.insertNewroad(newroad));
    }

    /**
     * 修改路段管理
     */
    @PreAuthorize("@ss.hasPermi('system:newroad:edit')")
    @Log(title = "路段管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Newroad newroad)
    {
        return toAjax(newroadService.updateNewroad(newroad));
    }

    /**
     * 删除路段管理
     */
    @PreAuthorize("@ss.hasPermi('system:newroad:remove')")
    @Log(title = "路段管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roadIds}")
    public AjaxResult remove(@PathVariable Long[] roadIds)
    {
        return toAjax(newroadService.deleteNewroadByRoadIds(roadIds));
    }
}
